<?php

namespace app\mobile\controller;

use app\common\controller\Frontend;
use think\Db;
use think\Request;

class Product extends Frontend
{

    protected $noNeedLogin = '*';
    protected $noNeedRight = '*';
    protected $layout = '';

    public function index()
    {
        $where=[
            'p.status'=>'2',
        ];
        
        if($this->request->has('category_id')){
            $ids=getChildIds($this->request->param('category_id/d'));

            array_push($ids, $this->request->param('category_id/d'));

            $where['p.category_id']=['in',$ids];
        }
        
        
		$rs_product=Db::name('product')->alias('p')
		->join('qiye q','p.qiye_id=q.id','LEFT')->field('p.*,q.name as qiye_name')
		->where($where)->order('weigh desc,updatetime desc')->paginate(10);
		$this->assign('product',$rs_product);
		$this->assign('empty','<div class="empty">
					<div>
						<img src="/mobile/img/ico_empty.png" >
						<p>没有查询到对应内容</p>
					</div>
				</div>');
        return $this->view->fetch();
    }
	
	public function detail(Request $request){
		$id=$request->param('id/d',0);
		$rs=Db::name('product')->alias('p')
		->join('qiye q','p.qiye_id=q.id','LEFT')->field('p.*,q.name as qiye_name')
		->order('weigh desc,updatetime desc')->where(['p.id'=>$id])->find();
		
		if(is_null($rs)){
			$this->error('内容不存在');
		}
		$this->assign('rs',$rs);

		return $this->view->fetch();
	}

}
